import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import picspro from '@/components/picspro'
import addgoods from '@/components/addgoods'
import editgoods from '@/components/editgoods'
import search from '@/components/search'


// import kregister from '@/components/kregister'
// import klogin from '@/components/klogin'

Vue.use(Router)

var routes = [
        // 考试
        // {
        //   path:'/kregister',
        //   name:'kregister',
        //   component:kregister
        // },
        // {
        //   path:'/klogin',
        //   name:'klogin',
        //   component:klogin
        // },
        {
          path:'/search',
          name:'search',
          component:search
        },
        {
          path:'/editgoods',
          name:'editgoods',
          component:editgoods
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
        {
          path:'/picspro',
          name:'picspro',
          component:picspro
        },
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        // 拦截器
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter:(to,from,next)=>{
            var uid = localStorage.getItem('username')
            if(uid){
              next();
            }else{
              next('/login');
            }

          }
        }
        
        
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
